package com.zzq.my.jetpacks.util

import android.content.Context
import androidx.annotation.DrawableRes
import androidx.annotation.NonNull
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager

/**
 * 描述：Rv 间隔线设置，一般可以通过drawable 设置高度，颜色等
<?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <size android:height="2dp" />
    <solid android:color="#eee" />
</shape>
 *  val drawable = ContextCompat.getDrawable(mContext, R.drawable.divider_mileage)
 *  dividerItemDecoration.setDrawable(drawable)
 * 作者：zhuangzeqin
 * 时间: 2021/12/24-10:54
 * 邮箱：zzq@eeepay.cn
 * 备注:
 * //DividerItemUtils.dividerItemDecorationTool(mContext)//默认的间隔线
   //DividerItemUtils.dividerItemDecorationTool(mContext,drawId=R.drawable.divider_mileage)//自定义间隔线
 */
object DividerItemUtils {
    @JvmStatic
    fun dividerItemDecorationTool(
        @NonNull context: Context,
        orientation: Int = LinearLayoutManager.VERTICAL,
        @DrawableRes drawId: Int?=null
    ): DividerItemDecoration {
        //默认的间隔线listDivider
        val  dividerItemDecoration = DividerItemDecoration(context, orientation)
        //设置自定义的间隔线
        drawId?.let {
            ContextCompat.getDrawable(context, it)
        }?.also {
            dividerItemDecoration.setDrawable(it)
        }
        return dividerItemDecoration
    }
}